package es.cazadoresmadridejos.beans.facade.partner;

import org.directwebremoting.annotations.RemoteProxy;
import org.directwebremoting.spring.SpringCreator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import es.cazadoresmadridejos.beans.manager.partner.PartnerManager;
import es.cazadoresmadridejos.model.Partner;

@Service
@RemoteProxy(name="partnerFacade",creator=SpringCreator.class)
public class PartnerFacade {

	@Autowired private PartnerManager partnerManager;

	public Boolean[] validateUser(String userid, Long id, Long partnerId){
		Boolean[] results = new Boolean[2];
		Partner partner = partnerManager.getByName(userid);
		if(partner == null){
			results[0] = true;
		}else if(id == null){
			results[0] =false;
		}else if(id.equals(partner.getId())){
			results[0] =true;
		}else{
			results[0] =false;
		}

		if(partnerId != null){
			Partner partnerPatner = partnerManager.get(partnerId);
			if(partnerPatner.getPartner() != null && !partnerPatner.getPartner().getId().equals(id)){
				results[1] = false;	
			}else{
				results[1] = true;	
			}
		}else{
			results[1] = true;
		}
		return results;
	}
}
